package com.scut.statistics_website.scheduler;

import com.scut.statistics_website.endpoint.WebSocketEndpoint;
import com.scut.statistics_website.service.FixedTimeInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.websocket.Session;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.logging.Logger;

@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class SendMessage {
    private static final Logger sysLogger = Logger.getLogger("sysLog");
    @Autowired
    private FixedTimeInfoService fixedTimeInfoService;

    @Scheduled(cron = "0/5 * * * * ?")
    private void configureTasks() {
//        List<Session> userSessions = WebSocketEndpoint.getUserSessions();
//        if(userSessions.size() > 0) {
//            for(Session session : userSessions) {
//                try {
//                    session.getBasicRemote().sendText("success fdff");
//                }
//                catch (IOException e){
//                    sysLogger.info("error in session");
//                }
//            }
//        }
    }
}
